package com.guoxue.util;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.guoxue.service.ITapesShareService;

import redis.clients.jedis.Jedis;
/**
 * 清理排行榜数据
 * @author Administrator
 *
 */
@Component
public class CleanThread extends Thread{
	@Resource
	private ITapesShareService tapesShareService;
	@Override
	public void run() {
		while(true){
			Jedis jedis = RedisUtil.getJedis();
			try {
				if (OtherUtils.dayForWeek()==7){
					String flag = jedis.get("isClean");
					if (flag==null||flag.equals("false")){
						int c = tapesShareService.changeWeeklyData();
						if (c>=0){
							jedis.set("isClean", "true");
							System.out.println("==================每周数据更新====================");
						}
					}
					if (flag.equals("true")){
						System.out.println("==================数据已更新====================");
					}
				}else{
					jedis.set("isClean", "false");
				}
			} catch (Exception e) {
				LoggerUtil.error(e);
			} finally {
				jedis.close();
			}
			try {
				CleanThread.sleep(1000*60*60*24);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
